package com.atguigu.cloud.controller;

import cn.hutool.core.date.DateUtil;
import com.atguigu.cloud.apis.PayFeignApi;
import com.atguigu.cloud.entities.PayDTO;
import com.atguigu.cloud.resp.ResultData;
import com.atguigu.cloud.resp.ReturnCodeEnum;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @className: OrderController
 * @author: 刘远鑫
 * @date: 2024/3/4
 **/

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    @Resource
    private PayFeignApi payFeignApi;

    @PostMapping("/feign/pay/add")
    public ResultData addOrder(@RequestBody PayDTO payDTO) {
        ResultData<String> add = payFeignApi.add(payDTO);
        return add;
    }

    @GetMapping("/feign/pay/getById/{id}")
    public ResultData getOrder(@PathVariable("id") Integer id) {
        ResultData getOrder = payFeignApi.selectPayById(id);
        return getOrder;
    }

    @GetMapping("/feign/pay/getInfoByConsul")
    public String getlb() {
        String getlb = payFeignApi.getlb();
        return getlb;
    }

    @GetMapping("/feign/pay/getAll")
    public ResultData getAll() {
        ResultData all=null;
        try {
            log.info("调用开始{}", DateUtil.now());
            all = payFeignApi.getAll();
            log.info("调用结束{}", DateUtil.now());
        }catch (Exception e){
            e.printStackTrace();
            log.error("{},{}",e.getMessage(),DateUtil.now());
            return ResultData.fail(ReturnCodeEnum.RC500.getCode(),e.getMessage());
        }

        return all;
    }



}
